#include "InputMesh.h"

InputMesh::InputMesh():m_VertexList(NULL),m_TrianglesData(NULL)
{
}

InputMesh::InputMesh(VertexList* vertices, TriangleList* triangles):m_VertexList(vertices)
{
	m_TriangleLists.push_back(triangles);
}

InputMesh::~InputMesh(void)
{
}

int InputMesh::GetNumFaces() const
{
	vector<TriangleList*>::const_iterator it;
	int count = 0;
	for ( it = m_TriangleLists.begin(); it != m_TriangleLists.end(); ++it)
	{
		count += (*it)->GetNumberOfPrimitives();
	}
	return count;
}

void* InputMesh::GetTrianglesPointer(){
	if (m_TriangleLists.size() == 1){
		TriangleList* tl = m_TriangleLists[0];
		return tl->GetData();
	}else{
		if ( m_TrianglesData == NULL )
		{
			int sizeInBytes=0;
			vector<TriangleList*>::const_iterator it;
			for ( it = m_TriangleLists.begin(); it != m_TriangleLists.end(); ++it)
			{
				sizeInBytes += (*it)->GetSizeInBytes();
			}
			m_TrianglesData = new byte[sizeInBytes];
			int offset = 0;
			for ( it = m_TriangleLists.begin(); it != m_TriangleLists.end(); ++it)
			{
				TriangleList* tl = *it;
				int sb = (*it)->GetSizeInBytes();
				memcpy_s(m_TrianglesData+offset,sb,tl->GetData(),sb);
				offset+=sb;
				m_TrianglesData;
			}
		}
		return m_TrianglesData;
	}
}